package woa.sort.test20230210;

import java.util.Arrays;

/**
 * @author wangpeng
 * @date 2023/2/10 15:48
 */
public class InsertSort1 {

    public static void sort(int[] arr) {
        if (arr == null || arr.length == 0) {
            return;
        }

        for (int i = 1; i < arr.length; i++) {
            int value = arr[i];
            int j = i - 1;
            for (; j >= 0; j--) {
                if (value < arr[j]) {
                    arr[j + 1] = arr[j];
                } else {
                    break;
                }
            }
            arr[j + 1] = value;
        }
    }

    public static void main(String[] args) {
        int[] arr = {3,4,1,3,5,6,78,1,3,3,3,2};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
